package com.gxar.quick.ar.server.base.common.enums;

import com.gxar.quick.ar.server.base.common.enums.order.OrderMethodEnum;

import java.util.Arrays;

/**
 * @author linsy
 * @version 1.0
 * @created 2024/2/21 11:24
 */
public enum ExchangeItemGiftEnum {
    OWN(0, "自己的"),
    TRANSFER(1, "转赠"),
    HANDSEL(2, "赠送"),
    ;
    private final Integer code;
    private final String name;

    /**
     * 根据code转枚举
     *
     * @param code code
     * @return 枚举
     */
    public static ExchangeItemGiftEnum getByCode(Integer code) {
        return Arrays.stream(ExchangeItemGiftEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    /**
     * 转换枚举，默认泛化他人转赠
     *
     * @param code code
     * @return 响应
     */
    public static OrderMethodEnum convertOrderMethodCodeByCode(Integer code) {
        if (ExchangeItemGiftEnum.HANDSEL.getCode().equals(code)) {
            return OrderMethodEnum.OTHERS_HANDSEL;
        } else {
            return OrderMethodEnum.OTHERS_TRANSFER;
        }
    }

    ExchangeItemGiftEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }
}
